import router from './index';
import store from '../store';
import NProgress from 'nprogress'; // 进度条
import Cookies from 'js-cookie';
import 'nprogress/nprogress.css'; // 进度条样式
import Vue from "vue";
import {selectCustomerByToken} from "@/http/api/customer";


NProgress.configure({ showSpinner: false });
router.beforeEach((to, from, next) => {
    NProgress.start();
    let token = Cookies.get("token");
    if (token){
        selectCustomerByToken(token).then(res=>{
            store.commit("setLoginCustomer",res.data);
            next();
        })
    }else {
        next();
    }
});
router.afterEach(() => {
    NProgress.done(); // 结束Progress
});
